package cn.tedu.jsd2209.csmall.product.web;

import cn.tedu.jsd2209.csmall.product.ex.ServiceException;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;
import lombok.experimental.Accessors;

import javax.sql.rowset.serial.SerialException;

@Data
@Accessors(chain = true)
public class JsonResult {
    private Integer state;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String massage;


    public static JsonResult ok(){
        JsonResult jsonResult = new JsonResult();
        jsonResult.state = ServiceCode.OK.getValue();
        return jsonResult;
    }
    public static JsonResult fail(ServiceException e){
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.state = e.getServiceCode().getValue();
//        jsonResult.massage = e.getMessage();
        return fail(e.getServiceCode(), e.getMessage());
    }
    public static JsonResult fail(ServiceCode serviceCode,String massage){
        JsonResult jsonResult = new JsonResult();
        jsonResult.state = serviceCode.getValue();
        jsonResult.massage = massage;
        return jsonResult;
    }
}
